<template>
  <div ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>
<script>
import BScroll from "@better-scroll/core";
import ObserveDOM from "@better-scroll/observe-dom";
import Pullup from "@better-scroll/pull-up";
BScroll.use(Pullup);
BScroll.use(ObserveDOM);
export default {
  data() {
    return {
      bs: null,
    };
  },
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    this.bs = new BScroll(this.$refs.wrapper, {
      pullUpLoad: this.pullUpLoad,
      probeType: this.probeType,
      pullUpLoad: true,
      scrollbar: true,
      pullDownRefresh: true,
      observeDOM: true, // 开启 observe-dom 插件
      click: true,
    });
    //监听组件滚动
    this.bs.on("scroll", (position) => {
      this.$emit("scroll", position);
    });
    //上拉触底触发
    this.bs.on("pullingUp", () => {
      console.log("1");
      this.$emit("pullingUp");
      this.bs.finishPullUp();
      this.bs.refresh();
    });
  },
  methods: {
    scrollTo(x, y, time = 300) {
      this.bs.scrollTo(x, y, time);
    },
  },
};
</script>
<style scoped>
</style>